<template>
	<view>
		<view class="content">
			<view class="tabs">
				<view class="tabs-1">
					<view v-for="(item, index) in tablist" :key="index" class="tabs-2"
						:class="{ 'active': isSelected === index }" @click="selectTab(index)">
						{{ item.name }}
					</view>
				</view>
			</view>
			<view class="item" v-for="(item,index) in serviceList" :key="index">
				<view class="c1">
					<view>
						<span class="c1-year">{{item.year}}</span> {{item.name}}
					</view>
					<view class="btn">
						<image @click="goPage(item)" class="btn1" src="https://pw.qyang.cc/static/icon-edit.png" mode="">
						</image>
						<switch color="#84E28D" :checked="item.is_open=='1'&&status==1" :disabled="status==2" style="transform:scale(0.6)" @change="setChange($event,item.id)" />
					</view>
				</view>
				<view class="c2">
					<view class="c2-text">
						抵扣金额：<span class="con2-text">{{item.area&&item.area.type=='DISCOUNT'?Number(item.area.discount):item.area.money}}</span>{{item.area&&item.area.type=='DISCOUNT'?'%':'元'}}
					</view>
					<view class="c2-text">
						满足额度：<span class="con2-text">{{item.area.min_money}}</span>元
					</view>
				</view>
				<view class="c2">
					<view class="c2-text">
						每人可领：<span class="con2-text">{{item.area.limit_use}}</span>
					</view>
					<view class="c2-text">
						有效天数：<span class="con2-text">{{item.expire_day}}</span>天
					</view>
				</view>
				<view class="c2">
					可用时间：{{item.start_time}}<span class="con2-text">（{{item.day}}天后可用）</span>
				</view>
				<view class="c3">
					>>小计：{{item.area.get_count}} 人领取、{{item.area.used_count}} 人使用<< </view>
						<u-line color="#E2E2E2" v-if="index!== serviceList.length - 1"></u-line>
				</view>
			</view>
		</view>
</template>

<script>
	export default {
		data() {
			return {
				isSelected: 0,
				tablist: [{
					name: '可使用'
				}, {
					name: '已过期'
				}],
				serviceList: [{
					year: '2025',
					name: '元旦快乐主题活动',
					show: '注册30天内',
					tiaojian: '不限制',
					time: '2024-07-01',
					time1: '领取时',
					day: '7',
					remark: '',
					num: '10',
					money: '800',
					money1: '100',
					bili: '',
					userNum1: '100',
					userNum2: '200'
				}, {
					year: '2025',
					name: '元旦快乐主题活动',
					show: '注册30天内',
					tiaojian: '不限制',
					time: '2024-07-01',
					time1: '领取时',
					day: '7',
					remark: '',
					num: '10',
					money: '800',
					money1: '100',
					bili: '',
					userNum1: '100',
					userNum2: '200'
				}],
				page:1,
				total:0,
				status:1,
				city_id:null
			};
		},
		onPullDownRefresh() {
			this.page = 1;
			uni.hideNavigationBarLoading();
			this.getService()
		},
		onReachBottom() {
			if (this.serviceList.length < this.total) {
				this.getService(true)
				this.page++;
			}
		},
		onLoad(e) {
			this.city_id = e.city_id			
		},
		onShow() {
			this.getService()
		},
		methods: {
			getService(more) {
				this.rq.getData('Coupon/index', { page: this.page,city_id:this.city_id,status:this.status }).then(res => {
					this.total = res.data.total
					if (more) {
						this.serviceList = this.serviceList.concat(res.data.data)
					} else {
						this.serviceList = res.data.data
					}
					uni.stopPullDownRefresh()
				}).catch(()=>{
					uni.stopPullDownRefresh()
				})
			},
			selectTab(index) {
				this.isSelected = index
				this.status = index==0?1:2
				this.page=1
				this.getService()
			},
			setChange(e,id) {
				console.log(e.detail.value,id);
				this.rq.getData('Coupon/open',{
					city_id:this.city_id,
					id:id,
					is_open:e.detail.value?1:0
				}).then(res=>{
					if(res.code==1){
						uni.showToast({
							title:`${e.detail.value?'已开启':'已关闭'}`,
							icon:'none'
						})
						this.getService()
					}
				})
			},
			goPage(item) {
				uni.navigateTo({
					url: `/subpages/proxyManage/quanEdit?id=${item.id}&city_id=${this.city_id}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		margin: 20rpx 40rpx 0;
		min-height: 98vh;
		border-radius: 10px;
		opacity: 1;
		background: #FFFFFF;

		.item {
			padding: 0 30rpx;

			.c1 {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-family: PingFang SC;
				font-size: 14px;
				font-weight: normal;
				line-height: 14px;
				letter-spacing: 0em;
				color: #333333;
				padding: 10rpx 0;

				.c1-year {
					color: #FF6666;
					margin-right: 10rpx;
				}

				.btn {
					display: flex;
					align-items: center;

					.btn1 {
						width: 40rpx;
						height: 40rpx;
					}
				}


			}

			.c2 {
				display: flex;
				align-items: center;
				font-family: PingFang SC;
				font-size: 14px;
				font-weight: normal;
				line-height: 20px;
				letter-spacing: 0em;
				color: #999999;
				height: 40rpx;
				padding: 10rpx 0;

				.c2-text {
					flex: 1;
				}

				.con2-text {
					color: #FF7883;
					margin-right: 10rpx;
				}
			}

			.c3 {
				font-family: PingFang SC;
				font-size: 12px;
				font-weight: normal;
				line-height: 12px;
				letter-spacing: 0em;
				font-variation-settings: "opsz" auto;
				color: #3886D6;
				text-align: center;
				padding: 10rpx 0 20rpx;
			}
		}
	}

	.tabs {
		background-color: #ffffff;
		padding: 10rpx 0;
		border-radius: 10px;

		.tabs-1 {
			display: flex;
			height: 50rpx;
			margin: 20rpx;
			align-items: center;
		}

		.tabs-2 {
			width: 140rpx;
			justify-content: center;
			align-items: center;
			display: flex;
			margin-right: 30rpx;
			font-family: PingFang SC;
			font-size: 15px;
			font-weight: normal;
			line-height: 15px;
			letter-spacing: 0px;
			color: #333333;
		}

		.tabs-2.active {
			position: relative;
			line-height: 15px;
			transition: all 0.3s ease;
			border-radius: 22px;
			opacity: 1;
			background: #FF7883;
			font-family: PingFang SC;
			font-size: 13px;
			font-weight: normal;
			letter-spacing: 0px;
			font-variation-settings: "opsz" auto;
			color: #FFFFFF;
			padding: 0 10rpx;
			height: 100%;
		}

		.tabs-icon {
			position: absolute;
			right: 40rpx;
			font-size: 20px;
		}
	}
</style>